package com.web.test.dao;

import com.web.test.bean.Message;
import com.web.test.bean.Middle;
import com.web.test.utils.JDBCUtil;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Created by Administrator on 2017/9/23.
 */
public class MiddleDao {

    // execute()返回boolean值，如果是查询返回true，如果是更新false
    public boolean insert(Middle middle) throws ClassNotFoundException,
            SQLException, IOException {

        Connection connection = JDBCUtil.getConnection();
        String sql = "insert into middle values(?,?,?,?)";
        PreparedStatement pStatement = connection.prepareStatement(sql);

        pStatement.setString(1, "");
        pStatement.setString(2, middle.getStuNo());
        pStatement.setString(3, middle.getQuestionNo());
        pStatement.setString(4,middle.getStuOptions());

        if (!pStatement.execute()) {
            JDBCUtil.close(connection, pStatement, null);
            return true;
        }

        return false;

    }

}
